package com.gxs.tga.examples;

import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.gxs.tga.examples.domain.Shop;
import com.gxs.tga.examples.domain.Track;
import com.gxs.tga.examples.service.ShopService;

@Component("personRestBean")
@Path("personRest")
public class PersonRest 
{
	
	 @Autowired  
     private ShopService shopService; 
	
	@GET
	@Path("test")
	// test url: http://localhost:8081/helloRest/test?param1=world
	public Response getExample(@QueryParam("param1") String param1)
	{
		Shop shop = new Shop();
		int id = (new Long(System.currentTimeMillis())).intValue();
		shop.setEmplNumber(id);
		shop.setId(id);
		shop.setName("Waqas: " + id);
		
		shopService.create(shop);
		
		System.out.println("Employee added with id: " + id);
		
		return Response.status(Status.OK).entity("hello person: " + param1).build();
	}
	
	@GET
	@Path("/track")
	@Produces(MediaType.APPLICATION_JSON)
	public Track getTrackInJSON() 
	{
 
		Track track = new Track();
		track.setTitle("Enter Sandman");
		track.setSinger("Metallica");
 
		return track;
 
	}
	
	@POST
	@Path("/track")
	@Consumes(MediaType.APPLICATION_JSON)
	public Response createTrackInJSON(Track track) 
	{
 
		String result = "Track saved : " + track;
		return Response.status(201).entity(result).build();
 	}

}
